package com.example.theme_hospital;

import javax.swing.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class HospitalGameFrame extends JFrame {
    private HospitalGamePanel gamePanel;
    
    public HospitalGameFrame() {
        initUI();
    }
    
    private void initUI() {
        setTitle("Theme Hospital - Simplified Version");
        setSize(800, 600);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        
        gamePanel = new HospitalGamePanel();
        add(gamePanel);
        
        // 添加键盘控制
        addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                handleKeyPress(e);
            }
        });
        
        setFocusable(true);
    }
    
    private void handleKeyPress(KeyEvent e) {
        int keyCode = e.getKeyCode();
        switch (keyCode) {
            case KeyEvent.VK_LEFT:
                gamePanel.moveDoctor(-1, 0);
                break;
            case KeyEvent.VK_RIGHT:
                gamePanel.moveDoctor(1, 0);
                break;
            case KeyEvent.VK_UP:
                gamePanel.moveDoctor(0, -1);
                break;
            case KeyEvent.VK_DOWN:
                gamePanel.moveDoctor(0, 1);
                break;
            case KeyEvent.VK_SPACE:
                gamePanel.diagnosePatient();
                break;
        }
    }
    
    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            HospitalGameFrame frame = new HospitalGameFrame();
            frame.setVisible(true);
        });
    }
}